<template>
	<view class="index">
		<view class="index-bg">
			<image src="../../static/bg.png" mode="widthFix"></image>
		</view>
		<view class="index-content">
			<view class="index-title">
				<view class="index-title-bg">
					观元山祠堂—-正言 正身 正人 正心
				</view>
			</view>
			
			<scroll-view class="scroll-view-gods" scroll-y="true" scroll-top="0">
				<view class="scroll-view-gods-item" v-for="(item, index) in imgList" :key="index" @click="showInfo">
					<view class="scroll-view-gods-item-item">
						<image class="scroll-view-gods-item-item-img" :src="item.content"></image>
					</view>
				</view>
			</scroll-view>
			
			<view class="index-gf">
				<image class="index-gf-xl" src="../../static/xl.gif"></image>
			</view>
			<view class="index-gf">
				<image class="index-gf-lz" src="../../static/lz.png"></image>
			</view>
			<view class="index-gf">
				<image class="index-gf-btn" src="../../static/btn.gif" @click="showWriteMsg"></image>
				
				<view class="msg-btn" style="color: #f3f3f3;" @click="showMsgList">查看留言</view>
			</view>
			
			
		</view>
		
		<uni-popup ref="msgList" type="center" :custom="true">
			<view class="msg-list">
				<view class="msg-list-bg">
					<view class="msg-list-content">
						<view class="msg-list-title">留言</view>
						<scroll-view class="msg-list-scroll" scroll-y="true" scroll-top="0">
							<view class="msg-list-item" v-for="(item, index) in msgList" :key="index">
								<view class="msg-list-item-content">{{item.content}}</view>
								<view class="msg-list-item-desc">{{item.name}} | {{item.createAt}}</view>
							</view>
							<view style="margin-top: 10rpx;">&nbsp;</view>
							<view style="font-size: 15px; display: flex;flex-direction: row;justify-content: center;" @tap="nextPageData()">{{netxStr}}</view>
						</scroll-view>
					</view>
				</view>
				<view class="msg-list-btns">
					<view class="btn">历史留言</view>
					<view class="btn close" @click="hideMsgList">关闭</view>
				</view>
			</view>
		</uni-popup>
		
		<uni-popup ref="info" type="center" :custom="true">
			<view class="msg-list">
				<view class="msg-list-bg">
					<view class="msg-list-content">
						<view class="msg-list-title">简介</view>
						<view class="msg-list-item">
							<view class="msg-list-item-content">观元山执元正司正回，元宵节叩拜元祖世</view>
						</view>
					</view>
				</view>
				<view class="msg-list-btns center">
					<view class="btn close" @click="hideInfo">关闭</view>
				</view>
			</view>
		</uni-popup>
		
		<uni-popup ref="writeMsg" type="center" :custom="true">
			<view class="write-msg">
				<view class="write-msg-content">
					<view class="write-msg-content-item">
						<view class="label">内容：</view>
						<view class="content">
							<view class="textarea"><textarea  v-model="tgctms.content"></textarea></view>
						</view>
					</view>
					<view class="write-msg-content-item flex">
						<view class="label">联系人：</view>
						<view class="content">
							<input  v-model="tgctms.name" type="text">
						</view>
					</view>
					<view class="write-msg-content-item flex">
						<view class="label">电    话：</view>
						<view class="content">
							<input  v-model="tgctms.phone"  type="text">
						</view>
					</view>
					<view class="write-msg-content-item flex">
						<view class="label">密    码：</view>
						<view class="content">
							<input  v-model="tgctms.pwd" type="password">
						</view>
					</view>
					<view class="write-msg-content-tips">{{msgTips}}</view>
					<view class="write-msg-btns center">
						<view class="btn" @tap="myctsubmit">提交</view>
						<view class="btn close" @click="hideWriteMsg">取消</view>
					</view>
				</view>
			</view>
		</uni-popup>
	</view>
</template>

<script>
	var http = require("../../utils/http.js");
	export default {
		data() {
			return {
				msgTips:'注明：手机、QQ、Email，是方便我们和您联系',
				tgctms:{},
				nextPage: 1,
				netxStr:'下一页',
				imgList: [],
				msgList: []
			}
		},
		onLoad() {
			this.loadmyctdataImg(1);
		},
		methods: {
			myctsubmit: function(opt) {
				var ths = this;
				if(!this.tgctms.content){
					ths.msgTips=  "内容必填";
					return;
				}
				if(!this.tgctms.name){
					ths.msgTips=  "姓名必填";
					return;
				}
				if(!this.tgctms.phone){
					ths.msgTips=  "联系方式必填";
					return;
				}
				
				var params = {
					url: "/api/mobile/myctsubmit?pwd="+this.tgctms.pwd,
					method: "POST",
					data: {
						"name": this.tgctms.name,
						"phone": this.tgctms.phone,
						"content": this.tgctms.content
					},
					callBack: res => {
						uni.showToast({
							title: "ssss",
							icon: "none"
						});
						console.log(res)
						if(res.code===0){
							ths.tgctms.content='';
							ths.tgctms.pwd='';
							ths.$refs.writeMsg.close()
							uni.showToast({
								title: "提交成功",
								icon: "none"
							});
						}else{
							ths.msgTips=  res.msg;
							uni.showToast({
								title: res.msg,
								icon: "none"
							});
						}
					}
				};
				http.request(params);
			},
			nextPageData:function(){
				this.loadmyctdata(this.nextPage);
			},
			loadmyctdata: function(page) {
				var _ths = this;
				var params = {
					url: '/api/mobile/loadmyctdata?limit=10&offset='+page,
					method: "POST",
					data: {},
					callBack: res => {
						 this.nextPage = this.nextPage+1;
						 var list = [];
						 if(res.code===0){
							if (res.data.pageNum === 1) {
								list = res.data.list;
							} else {
								if(page <= res.data.lastPage){
									list = this.msgList.concat(res.data.list)
								}else{
									this.netxStr="到底了~";
									return;
								}
								
							}
							this.msgList = list;
							
						 }
						 
					}
				};
				http.request(params);
			},
			loadmyctdataImg: function(page) {
				var _ths = this;
				var params = {
					url: '/api/mobile/loadmyctdataImg?limit=1000&offset='+page,
					method: "POST",
					data: {},
					callBack: res => {
						 var list = [];
						 if(res.code===0){
							if (res.data.pageNum === 1) {
								list = res.data.list;
							} else {
								if(page <= res.data.lastPage){
									list = this.imgList.concat(res.data.list)
								}else{
									this.netxStr="到底了~";
									return;
								}
								
							}
							this.imgList = list;
							
						 }
						 
					}
				};
				http.request(params);
			},
			showWriteMsg(){
				this.msgTips = '注明：手机、QQ、Email，是方便我们和您联系';
				this.$refs.writeMsg.open()
			},
			hideWriteMsg(){
				this.$refs.writeMsg.close()
			},
			showInfo(){
				this.$refs.info.open()
			},
			hideInfo(){
				this.$refs.info.close()
			},
			hideMsgList(){
				this.$refs.msgList.close()
			},
			showMsgList(){
				this.netxStr="下一页";
				this.msgList = [];
				this.nextPage=1;
				this.loadmyctdata(1)
				this.$refs.msgList.open()
			}
		}
	}
</script>

<style lang="scss">
.index {
	height: 100vh;
	overflow: hidden;
	&-bg{
		position: absolute;
		top: 0;
		left: 0;
		height: 100%;
		width: 100%;
		z-index: 0;
		overflow: hidden;
		image{
			width: 100%;
			height: 100%;
		}
	}
	&-content{
		position: absolute;
		z-index: 1;
		height: 100%;
		width: 100%;
		.scroll-view-gods {
			width: 88%;
			height: 484rpx;
			margin: 136rpx auto 0;
			&-item {
				display: inline-block;
				width: 23%;
				height: 217rpx;
				margin-bottom: 40rpx;
				padding-right: 10rpx;
				&:nth-child(4){
					padding-right: 0;
				}
				&-item{
					background: url(../../static/border.png) no-repeat;
					background-size: 100% 100%;
					padding: 12rpx 0rpx 4rpx 9rpx;
					&-img{
						width: 136rpx;
						height: 206rpx;
					}
				}
			}
		}
	}
	&-title{
		color: #D1AC75;
		text-align: center;
		padding: 10rpx 20rpx;
		&-bg{
			background: url(../../static/border2.png);
			background-size: 100% 100%;
			height: 60rpx;
			line-height: 60rpx;
		}
	}
	&-gf{
		position: absolute;
		bottom: 20rpx;
		width: 100%;
		text-align: center;
		&-lz{
			bottom: 10rpx;
			width: 100%;
		}
		&-xl{
			bottom: 100rpx;
			width: 750rpx;
			height: 619rpx;
		}
		&-btn{
			bottom:18rpx;
			width: 472rpx;
			height: 150rpx;
		}
		.msg-btn{
			position: relative;
			z-index: 10;
		}
	}
	.write-msg{
		width: 600rpx;
		background-color: #D1AC75;
		padding: 20rpx 30rpx 40rpx;
		border-radius: 23rpx;
		&-content{
			padding: 33rpx 20rpx;
			border: 3px solid #8A5509;
			border-radius: 20rpx;
			&-item{
				margin-bottom: 20rpx;
				.label{
					width: 150rpx;
					text-align-last: justify;
					text-align: justify;
					font-size: 26rpx;
					color: #95794F;
				}
				input{
					opacity: 1;
					padding: 10rpx 10rpx;
					font-size: 26rpx;
					width: 100%;
				}
				.textarea{
					background: #BC9760;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					padding: 10rpx;
					margin-top: 10rpx;
					textarea{
						width: 100%;
						font-size: 26rpx;
					}
				}
			}
			&-tips{
				font-size:20rpx;
				color: #8A5509;
				text-align: center;
			}
			.flex{
				display: flex;
				.content{
					background: #BC9760;
					border-radius: 12rpx 12rpx 12rpx 12rpx;
					flex: 1;
				}
			}
		}
		&-btns{
			margin-top: 20rpx;
			display: flex;
			justify-content: space-between;
			padding: 0 20rpx;
			.btn{
				width: 206rpx;
				height: 69rpx;
				background: #8A5509;
				border-radius: 14rpx 14rpx 14rpx 14rpx;
				opacity: 1;
				border: 6rpx solid #8A5509;
				text-align: center;
				line-height: 69rpx;
				color: #D1AC75;
				&.close{
					background-color: #D1AC75;
					color: #8A5509;
				}
			}
		}
	}
	.msg-list{
		width: 600rpx;
		background-color: #D1AC75;
		padding: 20rpx;
		&-bg{
			background: url(../../static/msg-bg.png);
			background-size: 100% 100%;
			width: 100%;
			height: 1000rpx;
		}
		&-content{
			padding: 33rpx 57rpx;
			height: 100%;
		}
		&-scroll{
			height: calc(100% - 150rpx);
		}
		&-title{
			font-size: 44rpx;
			color: #71400D;
			text-align: center;
		}
		&-item{
			margin-top: 20rpx;
			border-bottom: 1px solid #9F5F1E;
			padding-bottom: 10rpx;
			&-content{
				color: #732718;
				font-size: 30rpx;
				font-weight: 600;
			}
			&-desc{
				color: #95794F;
				font-size: 26rpx;
				margin-top: 10rpx;
			}
		}
		&-btns{
			margin-top: 20rpx;
			display: flex;
			justify-content: space-between;
			padding: 0 20rpx;
			&.center{
				justify-content: center;
			}
			.btn{
				width: 206rpx;
				height: 69rpx;
				background: #8A5509;
				border-radius: 14rpx 14rpx 14rpx 14rpx;
				opacity: 1;
				border: 6rpx solid #8A5509;
				text-align: center;
				line-height: 69rpx;
				color: #D1AC75;
				&.close{
					background-color: #D1AC75;
					color: #8A5509;
				}
			}
		}
	}
}

	
</style>
